package com.xneure.utils;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
/**
 * 
 * <p>支持中文配置文件工具，不用转码</p>
 *
 * <p>Copyright: 版权所有<br>
 *
 * @version 2018年8月16日
 */
public class ExtProperties extends java.util.Properties {

	private static final long serialVersionUID = -3121107460252555995L;

	public static ExtProperties readerPropertie(String path){
		return readerPropertie(path,"UTF-8");
	}
	public static ExtProperties readerPropertie(String path,String encodeType){
		try {
			ExtProperties propertiesUtil = new ExtProperties();
			propertiesUtil.reader(new InputStreamReader(ExtProperties.class.getResourceAsStream(path), encodeType));
			return propertiesUtil;
		} catch (UnsupportedEncodingException e) {
			return null;
		}
	}

	public static ExtProperties readerPropertie(Reader inputStreamReader) throws UnsupportedEncodingException {
		ExtProperties propertiesUtil = new ExtProperties();
		propertiesUtil.reader(inputStreamReader);
		return propertiesUtil;
	}

	private void reader(Reader inputStreamReader) {
		try {
			load(inputStreamReader);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	/**
	 * 根据key值取得对应的value值
	 * 
	 * @param key
	 * @return
	 */
	public String getValue(String key) {
		return getProperty(key);
	}

}
